home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / UTILITIES / BOGOMIPS.SPK / !Desk_Bogo / c / main < prev   
Text File  |  1996-04-28  |  3KB  |  122 lines

  1. /****************************************************************************/
  2. /* !Desk_Bogo - the desktop version                                         */
  3. /* Author   - Julyan Bristow                                                */
  4. /* Date     - April 1996                                                    */
  5. /* Version  - 1.00                                                          */
  6. /****************************************************************************/
  7.  
  8. #include "main.h"
  9. #include "bogomips.h"
  10.  
  11. /******************************** GLOBAL DATA *******************************/
  12.  
  13. char *Author  = "Julyan Bristow";
  14. char *Version = "1.00 - April 1996";
  15.  
  16. static dbox   dmain;
  17. unsigned long whole, fraction;
  18.  
  19. /**************************** GENERAL FUNCTIONS *****************************/
  20.  
  21. void result_to_string(char *format, ...)
  22. {
  23. char result[32];
  24. va_list va;
  25.  
  26.    va_start(va, format);
  27.    vsprintf(result, format, va);
  28.    va_end(va);
  29.    dbox_setfield(dmain, output_icon, result);
  30. }
  31.  
  32. static void info(void)
  33. {
  34.   dbox  d_info;
  35.   if (d_info = dbox_new("ProgInfo"), d_info != NULL)
  36.   {
  37.     dbox_setfield(d_info, Info_version, Version);
  38.     dbox_setfield(d_info, Author_field, Author);
  39.     dbox_show(d_info); dbox_fillin(d_info); dbox_dispose(&d_info);
  40.   }
  41. }
  42.  
  43. /****************************** EVENT HANDLERS ******************************/
  44.  
  45. static BOOL dmain_ehandler(dbox box, void *ev, void *handle)
  46. {
  47.   wimp_eventstr *e=(wimp_eventstr*) ev;
  48.   handle = handle;
  49.  
  50.   switch (e->e) {
  51.   case wimp_EOPEN:
  52.     wimp_open_wind(&e->data.o);
  53.     break;
  54.   case wimp_ECLOSE:
  55.     exit(0);            /* just quit */
  56.     break;
  57.   case wimp_EBUT:
  58.     switch (e->data.but.m.i) {
  59.       case start_icon:
  60.         dbox_setfield(dmain, output_icon, msgs_lookup("mess3"));
  61.         if (!bogo_mips_main(&whole, &fraction))
  62.           { werr(0,msgs_lookup("mess3")); exit(0);
  63.             break;
  64.           }
  65.         result_to_string("%s%u.%u",msgs_lookup("mess2"), whole, fraction);
  66.         break;
  67.       case cancel_icon:
  68.         exit(0);            /* just quit */
  69.         break;
  70.       case info_icon:
  71.         info();
  72.         break;
  73.       default:
  74.         break;
  75.     }
  76.   default:
  77.     break;
  78.   }
  79.   return TRUE;
  80. }
  81.  
  82. /****************************** INITIALISATION ******************************/
  83. static BOOL bogo_mips_initialise(void)
  84. {
  85. auto wimp_wstate boxstatus;
  86.  
  87.   wimpt_init("desk_bogo");
  88.   res_init("desk_bogo");
  89.   template_init();
  90.   dbox_init();
  91.   msgs_init();
  92.  
  93. /* create the main dialogue box */
  94.   if (dmain = dbox_new("Main"),dmain == 0) { werr(0, msgs_lookup("err1")); return (FALSE); }
  95.   dbox_raw_eventhandler(dmain, dmain_ehandler, 0);
  96.  
  97.   wimp_get_wind_state(dbox_syshandle(dmain), &boxstatus);
  98.   position_box(&boxstatus.o, MIDDLE_CENTRE);          /* get info to open error box in centre of screen */
  99.   wimp_open_wind(&boxstatus.o);          /* then open the window in that position */
  100.  
  101.   dbox_setfield(dmain, output_icon, msgs_lookup("mess1"));
  102.  
  103.   win_activeinc();
  104.  
  105.   return TRUE;
  106. }
  107.  
  108. /******************************* MAIN PROGRAM ********************************/
  109.  
  110. /*--- Main entry point. ---*/
  111. int main()
  112. {
  113.   if (bogo_mips_initialise())
  114.   {
  115.   event_setmask(wimp_EMPTRENTER|wimp_EMPTRLEAVE);
  116.     while (TRUE)
  117.       event_process();
  118.   }
  119.  
  120.   return FALSE;
  121. }
  122.